#!/bin/bash
# Kerberos ticket will never be expired
# author: zhchen@redhat.com

username=$1
read -s -p "Password: " password
echo

_kinit() {
	echo $password | kinit $username >/dev/null
}

forever_kinit() {
	while : ; do
		sleep 8h
		_kinit || exit 1
	done
}

# make sure password is correct
_kinit || exit 1

# then function can run in background forever, untill you kill it
trap "" HUP
forever_kinit & pid=$!

# save pid, in case you want to kill it easily
echo -n "Succeed! running forever_kinit in background, pid is: "
echo $pid | tee /tmp/klogin-$USER.pid

# and the script can exit.
exit 0
